package com.ty.springbootredis.service;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.io.Serializable;

/**
 * RedisService
 *
 * @aurhor Administrator  whs
 * @since 2024/9/25
 */
public class RedisService {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 添加
     */
    public boolean set(final String key, Object value) {
        boolean result = false ;
        try {
            ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
            operations.set(key, value);
            result = true;
        }catch (Exception e) {
            System.out.println("set error : key=" + key + ",value=" + value);
            e.printStackTrace();
        }
        return result;
    }

}
